﻿<style>
    .nameBox {
        border-style: solid;
        border-width: 1px;
        border-color: #95B8E7;
        cursor: pointer;
    }
</style>
<div class="datagrid-toolbar formToolBar">
    <a href="#" class="easyui-linkbutton" plain="true" onclick="save()" iconcls="iconfont iconfont-baocun">确定</a>
</div>
<div style="padding:2px;height:100%">
    <table class="groupTable" style="height:100%">
        <tr>
            <td id="fieldGroup" style="padding:2px;word-break:break-all;line-height:20px" colspan="3"></td>
        </tr>
        <tr>
            <td>
                <textarea id="Content" name="Content" style="width:100%;"></textarea>
            </td>
        </tr>
    </table>
</div>
<script>
    var formData = {};
</script>
<script>
    function pageLoad() {
        addFieldBox('FieldName', 'ColumnName');
        return;
        addAjaxParam("uiCode", queryString("UICode"));
        commitAjax("GetCtrlList", {
            CallBack: function (ctrlSettingObj) {
                if (ctrlSettingObj && ctrlSettingObj != '') {
                    {
                        $.each(ctrlSettingObj, function (index, item) {
                            addFieldBox(item.FieldName, item.ColumnName);
                        })
                    }
                }
                else {
                    msgBox('未找到UICode为' + queryString("UICode") + '的表单定义');
                }
            }
        })
    }

    function addFieldBox(fieldName, columnName) {
        var res = '';
        res += '<a class="nameBox" id="' + fieldName + '" onclick="selectFieldBox(this)">';
        res += fieldName;
        if (columnName && columnName != '') {
            res += '(' + columnName + ')';
        }
        res += '</a>&nbsp';
        $("#fieldGroup").append(res);
    }

    function selectFieldBox(obj) {
        setInputValue('Content','2333');
    }

    //了在IE、Firefox、Opera等主流浏览器的获取光标位置（getCursortPosition）以及设置光标位置（setCursorPosition）的函数
    //objid：textarea的id   str：要插入的内容
    function setInputValue(objid, str) {
        var myField = document.getElementById("" + objid);
        //IE浏览器
        if (document.selection) {
            myField.focus();
            sel = document.selection.createRange();
            sel.text = str;
            sel.select();
        }

            //火狐/网景 浏览器
        else if (myField.selectionStart || myField.selectionStart == '0') {
            //得到光标前的位置
            var startPos = myField.selectionStart;
            //得到光标后的位置
            var endPos = myField.selectionEnd;
            // 在加入数据之前获得滚动条的高度
            var restoreTop = myField.scrollTop;
            myField.value = myField.value.substring(0, startPos) + str + myField.value.substring(endPos, myField.value.length);
            //如果滚动条高度大于0
            if (restoreTop > 0) {
                // 返回
                myField.scrollTop = restoreTop;
            }
            myField.focus();
            myField.selectionStart = startPos + str.length;
            myField.selectionEnd = startPos + str.length;
        }
        else {
            myField.value += str;
            myField.focus();
        }
    }
</script>
